﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VCN.App.DataTransferObjects;

namespace VCN.App.DataAccessLayer
{
    public class ImageLogoDAO:BasicDAO<ImageLogo>
    {

        public List<ImageLogo> selectFilter2List(int ip_type)
        {
            return exeConvert(GetData("[sp_tblImageLogo_SelectByType]", "@Type", ip_type));
        }

        public ImageLogo selectImageLogoByID(int ip_Id)
        {
            List<ImageLogo> listImageLogo = exeConvert(GetData("[sp_tblImageLogo_SelectByID]", "@Id", ip_Id));
            if (listImageLogo == null || listImageLogo.Count == 0)
                return null;
            else
                return listImageLogo[0];
        }

        public List<ImageLogo> exeConvert(System.Data.DataTable ip_dt)
        {
            if (ip_dt == null)
            {
                return null;
            }
            else
            {
                List<ImageLogo> op_result = new List<ImageLogo>();
                for (int i = 0; i < ip_dt.Rows.Count; i++)
                {
                    op_result.Add(new ImageLogo(int.Parse(ip_dt.Rows[i]["Id"].ToString()),
                        ip_dt.Rows[i]["NAME"].ToString(), ip_dt.Rows[i]["URL_LOGO"].ToString(),
                        ip_dt.Rows[i]["IMAGE"].ToString(), int.Parse(ip_dt.Rows[i]["TYPE"].ToString()),
                       (bool)(ip_dt.Rows[i]["STATUS"]), (ip_dt.Rows[i]["Order"].ToString() == "") ? 0 : int.Parse(ip_dt.Rows[i]["Order"].ToString())));
                }
                return op_result;
            }
        }

        public override List<ImageLogo> selectAll2List(ImageLogo ip_obj)
        {
            throw new NotImplementedException();
        }

        public override bool update(ImageLogo ip_obj)
        {
            return (BasicDAO<ImageLogo>.ExecuteNonQuery("[sp_tblImageLogo_Update]", "@Id", ip_obj.Id,
                "@Name", ip_obj.Name, "@Image", ip_obj.Image, "@Order", ip_obj.Order, 
                "@Url_logo", ip_obj.Link, "@Type", ip_obj.Type, "@Status", ip_obj.Status) > 0);            
        }

        public override bool insert(ImageLogo ip_obj)
        {
            return (BasicDAO<ImageLogo>.ExecuteNonQuery("[sp_tblImageLogo_Insert]", "@Id", ip_obj.Id,
                "@Name", ip_obj.Name, "@Image", ip_obj.Image, "@Order", ip_obj.Order,
                "@Url_logo", ip_obj.Link, "@Type", ip_obj.Type, "@Status", ip_obj.Status) > 0);          
        }
    }
}
